// 模拟数据存储
let chatHistory = [
    {
        id: '1',
        inheritorId: 'default-1',
        senderType: 'inheritor',
        content: '欢迎咨询非遗技艺，请随时提问～',
        type: 'text',
        timestamp: new Date().toISOString()
    },
    {
        id: '2',
        inheritorId: 'default-1',
        senderType: 'user',
        content: '苏绣的基本针法有哪些？',
        type: 'text',
        timestamp: new Date().toISOString()
    }
];

// 获取历史记录
export const getChatHistory = (inheritorId) => {
    return chatHistory.filter(msg => msg.inheritorId === inheritorId);
};

// 发送消息
export const sendChatMessage = (inheritorId, content, type = 'text') => {
    const newMessage = {
        id: `msg-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
        inheritorId,
        senderType: 'user',
        content,
        type,
        timestamp: new Date().toISOString()
    };

    chatHistory.push(newMessage);

    // 模拟传承人自动回复
    setTimeout(() => {
        const replies = [
            `关于"${content}"，这项技艺的关键在于...`,
            '这个问题很好，我们通常的做法是...',
            '感谢您的关注，具体来说...',
            '我正在整理相关资料，稍后给您详细解答'
        ];
        const randomReply = replies[Math.floor(Math.random() * replies.length)];

        const replyMessage = {
            id: `msg-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
            inheritorId,
            senderType: 'inheritor',
            content: randomReply,
            type: 'text',
            timestamp: new Date().toISOString()
        };

        chatHistory.push(replyMessage);

        // 可选：添加图片自动回复示例
        // const imageReply = {
        //   id: `msg-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
        //   inheritorId,
        //   senderType: 'inheritor',
        //   content: 'https://via.placeholder.com/300x200?text=针法+图解',
        //   type: 'image',
        //   timestamp: new Date().toISOString()
        // };
        // chatHistory.push(imageReply);

    }, 1000);

    return true;
};
